/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.com.minam.jsp.controller;

import java.math.BigDecimal;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import pe.com.minam.beans.ScatbpCargo;

/**
 *
 * @author Alvaro
 */
public class ScatbpCargoConverter implements Converter {

    public Object getAsObject(FacesContext facesContext, UIComponent component, String string) {
        if (string == null || string.length() == 0) {
            return null;
        }
        BigDecimal id = new BigDecimal(string);
        ScatbpCargoController controller = (ScatbpCargoController) facesContext.getApplication().getELResolver().getValue(facesContext.getELContext(), null, "scatbpCargo");
        return controller.getJpaController().find(id);
    }

    public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
        if (object == null) {
            return null;
        }
        if (object instanceof ScatbpCargo) {
            ScatbpCargo o = (ScatbpCargo) object;
            return o.getIdCargo() == null ? "" : o.getIdCargo().toString();
        } else {
            throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: pe.com.minam.beans.ScatbpCargo");
        }
    }
    
}
